﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class admin_edintroduction : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        String id = Request.QueryString["id"] != null ? Request.QueryString["id"].ToString() : "";

        String lang = Request.QueryString["lang"] != null ? Request.QueryString["lang"].ToString() : "";
        String sql = "select * from [Introduction] where id = @id and lang = @lang";
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = cn;
        cmd.CommandText = sql;
        cmd.Parameters.AddWithValue("id", id);
        cmd.Parameters.AddWithValue("lang", lang);
        try
        {
            SqlDataReader rd = cmd.ExecuteReader();
            if (rd.HasRows)
            {
                rd.Read();
                hdfID.Value = rd.GetInt64(0) != null ? rd.GetInt64(0).ToString() : "";
                ddlLang.SelectedValue = rd.GetString(1) != null ? rd.GetString(1).ToString() : "";
                menu.Text = rd.GetString(2) != null ? rd.GetString(2).ToString() : "";
                title.Text = rd.GetString(3) != null ? rd.GetString(3).ToString() : "";
                fckContent.Value = rd.GetSqlString(4).ToString();
            }
            rd.Close();
            cn.Close();
        }
        catch (Exception ex)
        {
            Response.Redirect("Default.aspx?page=qlintroduction");
        }
    }
    protected void addbt_Click(object sender, EventArgs e)
    {
        hdfContent.Value = fckContent.Value;
        SqlDataSource3.Update();
        SqlDataSource3.DataBind();
        //Response.Write("<script>alert('Update Thành Công')</script>");
        Response.Redirect("Default.aspx?page=qlintroduction");
    }
}
